package com.dishdex.menuhub.module.module.dish.mapper;


import com.dishdex.menuhub.module.module.dish.entity.Dish;
import com.dishdex.menuhub.module.module.dish.request.DishDTO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * ClassName:
 * Package: com.dishdex.menuhub.mapper
 * Description:
 *
 * @Author:
 * @Create 2025/8/1 15:06
 * @Version 1.0
 */
@Mapper
public interface DishMapper {

    @Select("select cover_images,dish_name,dish_price,dish_score,dish_ingredients,dish_description," +
            "dish_review,create_time,update_time,category_id from dish where id =#{dishId} and is_deleted=0")
    Dish getById(@Param("dishId") Long dishId);

    @Select("select cover_images,dish_name,dish_price,dish_score,dish_ingredients," +
            "dish_description,dish_review,create_time,update_time,category_id from dish where id = #{dishId}")
    Dish extractById(@Param("dishId") Long dishId);

    int update(@Param("dish") Dish dish);

    int insert(@Param("dish") Dish dish);

    @Update("update dish set is_deleted=1 where id=#{dishId} and is_deleted=0")
    int delete(@Param("dishId") Long dishId);

    @Update("update dish set is_deleted=1 where category_id=#{categoryId} and is_deleted=0")
    int deleteByCategoryId(@Param("categoryId") Long categoryId);

    @Select("select id,cover_images,dish_name,dish_price,dish_score,dish_ingredients,dish_description," +
            "dish_review,create_time,update_time,category_id from dish " +
            "where category_id =#{categoryId} and is_deleted=0")
    List<Dish> getByCategoryId(@Param("categoryId") Long categoryId);

    List<Dish> getAllToAPP(@Param("dishPage") Integer dishPage,
                           @Param("pageSize") Integer pageSize,
                           @Param("keyword") String keyword,
                           @Param("ids") StringBuilder ids);

    List<DishDTO> getAllToConsole(@Param("dishPage") Integer dishPage,
                                  @Param("pageSize") Integer pageSize,
                                  @Param("keyword") String keyword);

    @Select("select count(*) from dish where is_deleted=0")
    Integer getTotal();

    Integer getLikeTotal(@Param("keyword") String keyword);

    @Select("select * from dish")
    List<Dish> getAll();

    int insertBatch(@Param("dishList") List<Dish> dishList);

    List<Dish> selectByMod(@Param("mod") int mod);
}
